﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using BUS;
using DTO;

namespace GUI
{
    public partial class FormCapNhatKhachHang : Form
    {
        public FormCapNhatKhachHang()
        {
            InitializeComponent();
        }
        //bien cuc bo
        public int makhachhang;
        public bool reset = false;
        //load combobox
        private void loadComboBoxTinhTrang()
        {
            DataTable dt = new DataTable();
            cmbTinhTrang.Items.Add("Chờ");
            cmbTinhTrang.Items.Add("Hoạt động");
            cmbTinhTrang.Items.Add("Khóa");

            cmbTinhTrang.SelectedIndex = 0;
        }

        private void btnOK_Click(object sender, EventArgs e)
        {
            string tinhtrang = cmbTinhTrang.Text.Trim();
            bool kq = KhachHangBUS.CapNhatTaiKhoan(makhachhang, tinhtrang);
            if (kq)
            {
                MessageBox.Show("Đã cập nhật.");
                reset = true;
                this.Dispose();
            }
            else
            {
                MessageBox.Show("Hủy giao tác.");
            }
        }

        private void btnCancel_Click(object sender, EventArgs e)
        {
            this.Dispose();
        }

        private void FormCapNhatKhachHang_Load(object sender, EventArgs e)
        {
            KhachHangDTO khachhangDTO = KhachHangBUS.ThongTinTaiKhoan(makhachhang);
            lbTenKhachHang.Text = khachhangDTO.TenKhachHang;
            loadComboBoxTinhTrang();

            for (int i = 0; i < cmbTinhTrang.Items.Count; i++)
            {
                if (khachhangDTO.TinhTrang.ToUpper().Equals(cmbTinhTrang.Items[i].ToString().ToUpper()))
                {
                    cmbTinhTrang.SelectedIndex = i;
                    break;
                }
            }
        }
    }
}
